#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

cv::Mat inverseColor1(cv::Mat srcImage) {
    // 通过 at 下标遍历
    cv::Mat tempImage.clone();
    int row = tempImage.rows;
    int col = tempImage.cols;

    // 遍历像素取反
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            tempImage.at<cv::Vec3b>(i, j)[0] = 255 - tempImage.at<Vec3b>(i, j)[0];
            tempImage.at<cv::Vec3b>(i, j)[1] = 255 - tempImage.at<Vec3b>(i, j)[1];
            tempImage.at<cv::Vec3b>(i, j)[2] = 255 - tempImage.at<Vec3b>(i, j)[2];
        }
    }

    return tempImage;
}

cv::Mat inverseColor3(cv::Mat srcImage){
    cv::Mat tempImage = srcImage.clone();
    int row = tempImage.rows;
    // 将三通道转换为单通道
    int nStep = tempImage.cols * tempImage.channels();
    for (int i=0; i<row; i++)
    {
        // 取愿图像的指针
        const uchar* pSrcData = srcImage.ptr<uchar>(i);
        // 将输出数据指针存放为输出图像
        uchar* pResultData = tempImage.ptr<uchar>(i);
        for (int j=0l j<nStep; j++)
        {
            pResultData[j] = cv::saturate_cast<uchar>(255-pSrcData[j]);
        }
    }

    return tempImage;
}